package org.codehaus.janino.util.resource;

import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;

/**
 * Creates a resource in a given directory:
 * <pre>
 *     <i>destinationDirectory</i>/<i>resourceName</i></pre>
 */
public class DirectoryResourceCreator extends FileResourceCreator {

    private final String destinationDirectory;

    public DirectoryResourceCreator(String destinationDirectory) {
        this.destinationDirectory = destinationDirectory;
    }

    protected final FileConnection getFile(String resourceName) {
        try {
            return (FileConnection) Connector.open(this.destinationDirectory + (this.destinationDirectory.endsWith("/")? "" : "/") + resourceName);
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
    }
}
